﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PwdMgr.Utility.Crypto;
using PwdMgr.Utility;
using PwdMgrUI.ViewModels;

namespace Test
{
    [TestClass]
    public class UtilityTest
    {
        [TestMethod]
        public void TestEncryptBasic()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            byte[] oriBuffer = new byte[256];
            for (int i = 0; i < oriBuffer.Length; i++)
                oriBuffer[i] = (byte)random.Next(0, 256);

            byte[] key = new byte[1024];
            for (int i = 0; i < key.Length; i++)
                key[i] = (byte)random.Next(0, 256);

            byte[] encrypted = CryptoUtil.Encrypt(oriBuffer, key);

            Assert.IsNotNull(encrypted);
            Assert.IsTrue(encrypted.Length > 0);

            byte[] decrypted = CryptoUtil.Decrypt(encrypted, key);

            Assert.IsNotNull(decrypted);
            Assert.IsTrue(decrypted.Length > 0);
            Assert.IsTrue(oriBuffer.ByteSequenceEqual(decrypted, oriBuffer.Length));
        }

        [TestMethod]
        public void TestViewModelBase()
        {
            LoginViewModel viewModel = new LoginViewModel();

            var cmd = viewModel.OKCommand;
            cmd.Execute(null);
        }
    }
}
